﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Client;

namespace PersApp
{
    public partial class AppForm : Form
    {
        // members
        UserRights user = UserRights.None; // права пользователя
        RepositoryManager RepMan = null; // объект для доступа к серверу

        public UserRights User
        {
            get { return user; }
        }

        public AppForm(UserRights userRights, RepositoryManager repManager)
        {
            InitializeComponent();

            user = userRights;
            RepMan = repManager;
        }

        private void моиДанныеToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string login, name, position = string.Empty;
            int salary = 0;

            Employee employee = RepMan.EmployeeRepository.GetData();
            login = employee.Login;
            name = employee.Name;

            IEnumerable<Position> positions = RepMan.PositionRepository.GetAll();
            foreach (Position p in positions)
                if (p.Id != employee.PositionId)
                {
                    position = p.Name;
                    salary = p.Salary;
                }

            UserDataForm userForm = new UserDataForm(user, login, name, position, salary);
            userForm.MdiParent = this;
            userForm.Text = "Мои данные:";
            userForm.Show();
        }
    }
}
